# -*- coding: utf-8 -*-
# @Time    : 2024/08/20 09:25
# @Author  : Jonny
# @File    : LuckPermissionHelperUtils.py
# @Describe: 检查权限辅助类

import requests
import json
import base64


class LuckPermissionHelperUtils(object):
    def __init__(self, config):
        self.config = config

    # 检查权限
    def check_permission(self, appkey, appsecret):
        auth = str(base64.b64encode(f'{self.config["log_url_basic_auth1"]}:{self.config["log_url_basic_auth2"]}'.encode('utf-8')), 'utf-8')
        headers = {
            'Content-Type': self.CONTENT_TYPE,
            'Authorization': f'Basic {auth}'
        }
        url = f'{self.config["log_url"]}/sys/app/checkPermission'

        parameters = {
            "appkey": appkey,
            "appsecret": appsecret
        }
        res = requests.post(url, data=json.dumps(parameters), headers=headers)
        return res.json()
